home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWStream / Include / FWObjReg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  2.9 KB  |  107 lines  |  [TEXT/MPS ]

  1. #ifndef FWOBJREG_H
  2. #define FWOBJREG_H
  3. //========================================================================================
  4. //
  5. //    File:                FWObjReg.h
  6. //    Release Version:    $ 1.0d11 $
  7. //
  8. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWSTDDEF_H
  13. #include "FWStdDef.h"
  14. #endif
  15.  
  16. #if FW_LIB_EXPORT_PRAGMAS
  17. #pragma lib_export on
  18. #endif
  19.  
  20. //========================================================================================
  21. // CLASS FW_CObjectRegistry
  22. //========================================================================================
  23.  
  24. class FW_CLASS_ATTR FW_CObjectRegistry
  25. {
  26. public:
  27.  
  28.     FW_CObjectRegistry();
  29.     virtual ~FW_CObjectRegistry();
  30.     
  31.     typedef long ID;
  32.     
  33.     enum {kNotInRegistry = -1};
  34.     
  35.     virtual FW_CObjectRegistry::ID Register(const void *object) = 0;
  36.         // Register an object and returns the (unique) ID
  37.     
  38.     virtual void Register(const void *object, FW_CObjectRegistry::ID id) = 0;
  39.         // Register an object to particular id.
  40.         // The id must not already be in the registry.
  41.     
  42.     virtual FW_CObjectRegistry::ID Lookup(const void *object) = 0;
  43.         // Look up an object in the registry, return kNonInRegistry if object not found.
  44.  
  45.     virtual const void* Lookup(FW_CObjectRegistry::ID id) = 0;
  46.         // Find an object by ID, return its pointer.
  47.         // Return 0 if id not in registry.
  48. };
  49.  
  50. //========================================================================================
  51. // CLASS FW_CBasicObjectRegistry
  52. //========================================================================================
  53.  
  54. class FW_CLASS_ATTR FW_CBasicObjectRegistry : public FW_CObjectRegistry
  55. {
  56. public:
  57.  
  58.     FW_CBasicObjectRegistry();
  59.     virtual ~FW_CBasicObjectRegistry();
  60.     
  61.     virtual FW_CObjectRegistry::ID Register(const void *object);
  62.         // Register an object and return its ID.
  63.     
  64.     virtual void Register(const void *object, FW_CObjectRegistry::ID id);
  65.         // Register an object to particular id
  66.     
  67.     virtual FW_CObjectRegistry::ID Lookup(const void *object);
  68.         // Look up an object in the registry, return kNonInRegistry if object not found.
  69.  
  70.     virtual const void* Lookup(FW_CObjectRegistry::ID id);
  71.         // Find an object by ID, return its pointer.
  72.         // Return 0 if id not in registry.
  73.  
  74. private:
  75.  
  76.     void GrowList();
  77.         // Grow the list by kExpansion slots
  78.     
  79.     struct SAssociation
  80.     {
  81.         FW_CObjectRegistry::ID    fID;            // object id
  82.         const void*                fObject;        // object address
  83.     };
  84.  
  85.     void InitAssociation(SAssociation& assoc)
  86.     {
  87.         assoc.fID = kNotInRegistry;
  88.         assoc.fObject = 0;
  89.     }
  90.  
  91.     enum {kExpansion = 8};
  92.     SAssociation*             fList;
  93.     long                    fListLength;
  94.     long                    fPhysicalListLength;
  95.     FW_CObjectRegistry::ID    fNextUnusedID;
  96.  
  97.     FW_CBasicObjectRegistry(const FW_CBasicObjectRegistry& readableStream);
  98.     FW_CBasicObjectRegistry& operator=(const FW_CBasicObjectRegistry& registry);
  99.         // Copy constructor and assignment operator not valid for this class.
  100. };
  101.  
  102. #if FW_LIB_EXPORT_PRAGMAS
  103. #pragma lib_export off
  104. #endif
  105.  
  106. #endif
  107.